home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls044.sh (.txt) < prev    next >
Microsoft Windows Help File Content  |  1994-09-02  |  7KB  |  180 lines

  1. #    @(#) postscript 23.3 91/10/07 
  2. #    Copyright (C) 1989-1991 The Santa Cruz Operation, Inc.
  3. #        All Rights Reserved.
  4. #    The information in this file is provided for the exclusive use of
  5. #    the licensees of The Santa Cruz Operation, Inc.  Such users have the
  6. #    right to use, modify, and incorporate this code into other products
  7. #    for purposes authorized by the license agreement provided they include
  8. #    this notice and the associated copyright notice with any such product.
  9. #    The information in this file is provided "AS IS" without warranty.
  10. #    lp interface for postscript printer
  11. #     arg1 is print job id
  12. #     arg2 is login of user who submitted job
  13. #     arg3 is title ???
  14. #     arg4 is the number of copies to print
  15. #     arg5 is a list of the -o options passed
  16. #     arg6... are paths to files to be printed
  17. #  Modifications"
  18. #  93/12/19 Terry B. Rhodes (tbr@88open.org)
  19. #  this program attempts to find a %! (as in %!PS-Adobe) in the
  20. #  first non-blank line of the file.  If it does it assumes the
  21. #  file is raw postscript and prints it as such. Otherwise the
  22. #  file is treated as text and an appropriate postscript header
  23. #  is added.  This all works fine unless the %! doesnt really
  24. #  describe a postscript file or unless you want the actual
  25. #  postscript program to print instead of be interpreted.
  26. #  In these cases you should use the
  27. #        -o raw
  28. #  option to get textual output of the submitted file.
  29. #  -o options not supported include , nofilebreak, length, width,
  30. #      lpi, cpi, stty
  31. #  this probably should have all these, fonts and other nice options
  32. #  too, wouldn't be too hard to add.
  33. # usage: FileIsPostscript FILEPATH
  34. # if %! appears in the first non-blank line of the file
  35. # we assume the file is a postscript program
  36. # Many programs only scan the first 4 chars of the first line
  37. # this doesnt appear good enough for dos/windows driver output
  38. FileIsPostscript()
  39. Z="`awk <$1 2>/dev/null '
  40.    if ( NF < 1)
  41.       { next; }
  42.    if ( index($0, "%!") != 0 )
  43.       { printf("true"); }
  44.    exit
  45. $DEBUG && awk <$1 2>/dev/null '
  46.     print $0
  47.    if ( NF < 1)
  48.       { next; }
  49.    if ( index($0, "%!") != 0 )
  50.       { printf("true"); }
  51.    exit
  52. ' >>/tmp/$PRINTER.out
  53. [ "$Z" = "true" ] && return 0
  54. return 1
  55. PrintBannerPages()
  56. # nhead gets the value of BANNERS or 1 by default
  57. nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
  58. [ "$nhead" -eq 0 ] && nhead=1
  59. [ "$nhead" -gt 5 ] && nhead=0
  60. if [ "$nhead" -gt 0 ]
  61.     # get the local system id
  62.     if test -r /etc/systemid
  63.     then
  64.         sysid=`sed 1q /etc/systemid`
  65.     else
  66.         sysid=`uname -n`
  67.     # user = fifth field of /etc/passwd
  68.     user=`sed -n "s/^$USER:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`
  69.     # todays date
  70.     tdate=`date`
  71.     while [ "$nhead" -gt 0 ]
  72.         echo "%!"
  73.         echo "/i{72 mul}def"
  74.         echo "/m{moveto}def"
  75.         echo "/s{show}def"
  76.         echo "/o{true charpath stroke}def"
  77.         echo "/rct{moveto dup neg 3 1 roll 0 exch rlineto"
  78.         echo "  0 rlineto 0 exch rlineto closepath}def"
  79.         echo "6.5 i 1.1 i 0.95 i 8.9 i rct 0.0 setgray stroke"
  80.         echo "6.5 i 1.1 i 0.95 i 8.9 i rct 0.8 setgray fill"
  81.         echo "/Helvetica-Bold findfont 45 scalefont setfont"
  82.         echo "1.0 setgray ($USER) 1.0 i 9.5 i m s"
  83.         echo "0.0 setgray ($USER) 1.0 i 9.5 i m o"
  84.         echo "/Helvetica findfont 20 scalefont setfont"
  85.         echo "($user) 1.0 i 9.0 i m s"
  86.         echo "(Request id: $JOBID) 1.0 i 8.5 i m s"
  87.         echo "(Copies: $NUMCOPIES) 1.0 i 8.0 i m s"
  88.         echo "(Options: $OPTIONS) 1.0 i 7.5 i m s"
  89.         echo "(Machine: $sysid) 1.0 i 7.0 i m s"
  90.         echo "(Date: $tdate) 1.0 i 6.5 i m s"
  91.         [ "$TITLE" ] && 
  92.             echo "(Title: $TITLE) 1.0 i 6.0 i m s"
  93.         echo "showpage"
  94.         nhead=`expr $nhead - 1`
  95.     done  
  96. # main()
  97. #stty exta clocal hupcl cs8 cread icanon ixon icrnl 0<&1
  98. #stty exta -opost onlcr tab3 ixon -echo ixany -ixoff -parity -hupcl 0<&1
  99. #stty 9600 clocal hupcl cs8 cread icanon ixon ixoff icrnl 0<&1
  100. stty ixon ixoff 0<&1
  101. # print job defaults
  102. MODE=port  # print in portrait mode
  103. RAW=false  # process file as text file
  104. PRTBANNER=true
  105. nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
  106. [ "$nhead" -eq 0 ] && PRTBANNER=false
  107. # DEBUG=true
  108. DEBUG=false
  109. PRINTER=`basename $0`
  110. $DEBUG && date >>/tmp/$PRINTER.out
  111. $DEBUG && echo "$*" >>/tmp/$PRINTER.out
  112. JOBID="$1" ; shift
  113. $DEBUG && echo "JOBID is $JOBID" >>/tmp/$PRINTER.out
  114. USER="$1" ; shift
  115. $DEBUG && echo "USER is $USER" >>/tmp/$PRINTER.out
  116. TITLE="$1" ; shift
  117. $DEBUG && echo "TITLE is $TITLE" >>/tmp/$PRINTER.out
  118. NUMCOPIES="$1" ; shift
  119. [ "$NUMCOPIES" -lt 1 ] && NUMCOPIES=1
  120. $DEBUG && echo "NUMCOPS is $NUMCOPIES" >>/tmp/$PRINTER.out
  121. OPTIONS="$1" ; shift
  122. $DEBUG && echo "OPTIONS is $OPTIONS" >>/tmp/$PRINTER.out
  123. FILES="$*"
  124. $DEBUG && echo "FILES is $FILES" >>/tmp/$PRINTER.out
  125. for OPTION in $OPTIONS
  126.     case $OPTION in
  127.         [Rr]aw | RAW | [Gg] )  RAW=true ;;
  128.         [Ll]and*2 | LAND*2 | [Ll]2 )  MODE=land2 ;;
  129.         [Ll]and* | LAND* | [Ll] )  MODE=land ;;
  130.         [Pp]ort* | PORT* | [Pp] )  MODE=port ;;
  131.       [Bb]an* | BAN* | [Bb] )     PRTBANNER=true ;;
  132.       [Nn]o[Bb]an | NOBAN* | [Nn][Bb] )   PRTBANNER=false ;;
  133.         # these are tbr options
  134.         132 )    MODE=land ;;
  135.         sideways ) MODE=land ;;
  136.     esac
  137. export MODE
  138. # the default text to postscript filter.
  139. TEXTFILTER=/usr/spool/lp/bin/text2post
  140. #Set up the default filter.
  141. if [  -x "${LOCALPATH}/lp.cat" ]
  142.     LPCAT="${LOCALPATH}/lp.cat 0"
  143.     LPCAT="cat"
  144. #If we are not using an output filter, use the default one.
  145. [ -z "${FILTER}" ] && FILTER="${LPCAT}"
  146. # this all appears to support drain.output, which is not needed ???
  147. # ${SPOOLDIR:=/usr/spool/lp}
  148. # ${LOCALPATH:=${SPOOLDIR}/bin}
  149. DRAIN=""
  150. [ -x "${LOCALPATH}/drain.output" ] && DRAIN="${LOCALPATH}/drain.output 1"
  151. echo "\004\c"                        # M003
  152. $DEBUG && echo "FILTER is $FILTER" >>/tmp/$PRINTER.out
  153. $DEBUG && echo "TEXTFILTER is $TEXTFILTER" >>/tmp/$PRINTER.out
  154. $PRTBANNER && PrintBannerPages
  155. i=1; FF=false
  156. while [ $i -le $NUMCOPIES ]
  157.     for FILE in $FILES
  158.         PRINTRAW=$RAW
  159.         if FileIsPostscript $FILE
  160.         then
  161.             $DEBUG && echo "$FILE is a postscript file" >>/tmp/$PRINTER.out
  162.             # switch the semantics on postscript files
  163.             # so -o raw prints the postscript code
  164.             PRINTRAW=true ; $RAW && PRINTRAW=false
  165.         if $PRINTRAW
  166.         then
  167.             $DEBUG && echo "Printing $FILE in raw mode" >>/tmp/$PRINTER.out
  168.             0<${FILE} eval ${FILTER} 2>&1
  169.         else
  170.             $DEBUG && echo "Printing $FILE in text mode" >>/tmp/$PRINTER.out
  171.             $FF && echo "\014"
  172.             0<${FILE} eval ${FILTER} 2>&1 | $TEXTFILTER
  173.     done
  174.     i=`expr $i + 1` ; FF=true
  175. done 
  176. echo "\004\c"                            # M003
  177. #Draining characters might be necessary.
  178. ${DRAIN}
  179. exit 0
  180.